<?php

/**
 * Controller Plugin to automatically choose the
 * layout according to the selected module
 *
 * @author neozilon
 */
class Nosql_Controller_Plugin_LayoutPicker extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName();
        $controller = $request->getControllerName();
        $layout = $module;

        if ($controller == 'error' && $module == 'admin'){
            $layout = 'error-admin';
        }

        Zend_Layout::getMvcInstance()->setLayout( $layout );
        if($request->isXmlHttpRequest()) {
            Zend_Layout::getMvcInstance()->disableLayout();
        }
    }

}
?>
